<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{:__('Installing BiuCMS')}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
    <meta name="renderer" content="webkit">
    <link href="install/css.css" rel="stylesheet">
</head>

<body>
<div class="container">
    <h1>
        <svg width="90px" height="90px" viewBox="0 0 90 90" version="1.1" xmlns="http://www.w3.org/2000/svg">
            <rect x="0" y="0" width="90" height="90" rx="15" ry="15" fill="#4e73df"/>
            <text x="50%" y="50%" font-family="Arial" font-size="40" fill="#FFFFFF" text-anchor="middle"
                  dominant-baseline="central">Biu
            </text>
        </svg>
    </h1>
    <h2>{:__('Installing BiuCMS')}</h2>
    <div>
        <form method="post">
            <div id="step-title"><img id="step_img" src="/install/images/step_{$step|default=1}.png"></div>
            <div style="clear: both;"></div>
            {if $errInfo}
            <div class="error">
                {$errInfo}
            </div>
            {/if}
            <div id="error"></div>
            <div id="success">{:__('Install Successed')}</div>
            <div id="warmtips"></div>
            <div style="clear: both;"></div>
            {if $step==1}
            <div class="form-group">
                <table class="environment-table" cellspacing="1">
                    <tr>
                        <td class="td1">环境检测</td>
                        <td class="td1" style="width:30%">推荐配置</td>
                        <td class="td1" style="width:45%">当前状态</td>
                    </tr>
                    <tr>
                        <td class="first">服务器环境</td>
                        <td>apache2.0以上/nginx1.6以上/IIS</td>
                        <td>{:$_SERVER['SERVER_SOFTWARE']}</td>
                    </tr>
                    <tr>
                        <td class="first">PHP版本</td>
                        <td>{$min_php|default=""}及{$min_php|default=""}以上</td>
                        <td>{$php_ver|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">safe_mode</td>
                        <td class="hander" title="影响缓存清除、系统升级、模板管理等功能">基础配置</td>
                        <td>{$safe_mode|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">GD库</td>
                        <td class="hander" title="影响验证码是否显示、图片水印、以及图像处理等问题">必须开启</td>
                        <td>{$gd|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">session</td>
                        <td class="hander" title="影响系统安装、后台登录等功能">必须开启</td>
                        <td>{$session|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">mysqli</td>
                        <td class="hander" title="影响数据库的连接和一系列读、写、删、改操作">必须开启</td>
                        <td>{$mysql|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">pdo</td>
                        <td class="hander" title="影响数据库的连接和一系列读、写、删、改操作">必须开启</td>
                        <td>{$pdo|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">pdo_mysql</td>
                        <td title="影响数据库的连接和一系列读、写、删、改操作">必须开启</td>
                        <td>{$pdo_mysql|default=""}</td>
                    </tr>
                    <tr>
                        <td class="td1">函数检测</td>
                        <td class="td1">推荐配置</td>
                        <td class="td1">当前状态</td>
                    </tr>
                    <tr>
                        <td class="first">curl_init</td>
                        <td class="hander" title="影响插件功能、伪静态、系统升级、采集文章等功能">必须开启</td>
                        <td>{$curl|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">file_put_contents</td>
                        <td class="hander" title="影响系统安装、文件上传、数据库备份、百度地图xml等功能">必须开启</td>
                        <td>{$file_put_contents|default=""}</td>
                    </tr>
                    <tr>
                        <td class="first">scandir</td>
                        <td class="hander" title="影响读取指定文件夹中的文件和子目录名称功能">必须开启</td>
                        <td>{$scandir|default=""}</td>
                    </tr>
                    <tr>
                        <td class="td1">目录、文件权限检测</td>
                        <td class="td1">推荐配置</td>
                        <td class="td1">当前状态</td>
                    </tr>
                    {volist name="dirs" id="dir"}
                    <tr>
                        <td class="first">{$dir["name"]|default=""}</td>
                        <td class="hander" title="{$dir['title']}">{:__($dir["rights"])}</td>
                        <td>{$dir["status"]|default=""}</td>
                    </tr>
                    {/volist}
                </table>
            </div>
            <div class="form-buttons">
                <input type="button" value="{:__('Install Next Step')}" class="btn btn-next"/>
            </div>
            {elseif $step==2}
            <div class="form-group">
                <div class="form-field">
                    <label>{:__('Mysql Hostname')}</label>
                    <input type="text" name="mysqlHostname" value="127.0.0.1" required="">
                </div>

                <div class="form-field">
                    <label>{:__('Mysql Database')}</label>
                    <input type="text" name="mysqlDatabase" value="biu_cms" required="">
                </div>

                <div class="form-field">
                    <label>{:__('Mysql Username')}</label>
                    <input type="text" name="mysqlUsername" value="root" required="">
                </div>

                <div class="form-field">
                    <label>{:__('Mysql Password')}</label>
                    <input type="password" name="mysqlPassword">
                </div>

                <div class="form-field">
                    <label>{:__('Mysql Prefix')}</label>
                    <input type="text" name="mysqlPrefix" value="biu_">
                </div>

                <div class="form-field">
                    <label>{:__('Mysql Hostport')}</label>
                    <input type="number" name="mysqlHostport" value="3306">
                </div>
                <div class="form-field">
                    <label>{:__('Admin Username')}</label>
                    <input name="adminUsername" value="admin" required=""/>
                </div>

                <div class="form-field">
                    <label>{:__('Admin Email')}</label>
                    <input name="adminEmail" value="admin@admin.com" required="">
                </div>

                <div class="form-field">
                    <label>{:__('Admin Password')}</label>
                    <input type="password" name="adminPassword" required="" value="">
                </div>

                <div class="form-field">
                    <label>{:__('Repeat Password')}</label>
                    <input type="password" name="adminPasswordConfirmation" required="" value="">
                </div>
                <div class="form-field">
                    <label>{:__('Website')}</label>
                    <input type="text" name="siteName" value="{:__('My Website')}" required=""/>
                </div>

            </div>
            <div class="form-buttons">
                <input type="button" value="{:__('Install Previous Step')}" class="btn btn-previous"/>
                <button type="submit">{:__('Install now')}</button>
            </div>
            {/if}
        </form>

        <!-- jQuery -->
        <script src="__ROOT__/assets/libs/jquery/dist/jquery.min.js"></script>

        <script>
            $(function () {
                $('form :input:first').select();
                $(".btn-next").click(function(){
                    location.href = "?step=2";
                });
                $(".btn-previous").click(function(){
                    location.href = "?step=1";
                });

                $('form').on('submit', function (e) {
                    e.preventDefault();
                    var form = this;
                    var $error = $("#error");
                    var $previous = $(".btn-previous");
                    var $button = $(this).find('button')
                        .text("{:__('Installing')}")
                        .prop('disabled', true);
                    $previous.hide();
                    $.ajax({
                        url: "",
                        type: "POST",
                        dataType: "json",
                        data: $(this).serialize(),
                        success: function (ret) {
                            if (ret.code == 1) {
                                var data = ret.data;
                                $error.hide();
                                $(".form-group", form).remove();
                                $button.remove();
                                $previous.remove();
                                $("#success").text(ret.msg).show();
                                $("#step_img").attr("src","/install/images/step_3.png");

                                $buttons = $(".form-buttons", form);
                                $("<a class='btn' href='./'>{:__('Home')}</a>").appendTo($buttons);

                                if (typeof data.adminName !== 'undefined') {
                                    var url = location.href.replace(/install\.php/, data.adminName);
                                    url = url.split("?")[0];
                                    $("#warmtips").html("{:__('Security tips')}" + '<a href="' + url + '">' + url + '</a>').show();
                                    $('<a class="btn" href="' + url + '" id="btn-admin" style="background:#4e73df">' + "{:__('Dashboard')}" + '</a>').appendTo($buttons);
                                }
                                localStorage.setItem("fastep", "installed");
                            } else {
                                $error.show().text(ret.msg);
                                $previous.show();
                                $button.prop('disabled', false).text("{:__('Install now')}");
                                $("html,body").animate({
                                    scrollTop: 0
                                }, 500);
                            }
                        },
                        error: function (xhr) {
                            $previous.show();
                            $error.show().text(xhr.responseText);
                            $button.prop('disabled', false).text("{:__('Install now')}");
                            $("html,body").animate({
                                scrollTop: 0
                            }, 500);
                        }
                    });
                    return false;
                });
            });
        </script>
    </div>
</div>
</body>
</html>
